<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Registers the script with the SCM, so that it can act as the service with the given name</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.win32-start-service-ctrl-dispatcher" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">win32_start_service_ctrl_dispatcher</h1>
  <p class="verinfo">(PECL win32service &gt;=0.1.0)</p><p class="refpurpose"><span class="refname">win32_start_service_ctrl_dispatcher</span> &mdash; <span class="dc-title">Registers the script with the SCM, so that it can act as the service with the given name</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.win32-start-service-ctrl-dispatcher-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>win32_start_service_ctrl_dispatcher</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$gracefulMode</code><span class="initializer"> = true</span></span>
  ] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>


  <p class="para rdfs-comment">
   When launched via the Service Control Manager, a service process is
   required to &quot;check-in&quot; with it to establish service monitoring and
   communication facilities.  This function performs the check-in by spawning
   a thread to handle the lower-level communication with the service control
   manager.
  </p>
  <p class="para">
   Once started, the service process should do 2 things. The first is to tell
   the Service Control Manager that the service is running. This is achieved
   by calling <span class="function"><a href="win32_set_service_status.html" class="function">win32_set_service_status()</a></span> with the
   <strong><code>WIN32_SERVICE_RUNNING</code></strong> constant. If you need to perform
   some lengthy process before the service is actually running, then you can
   use the <strong><code>WIN32_SERVICE_START_PENDING</code></strong> constant. The
   second is to continue to check-in with the service control manager so that
   it can determine if it should terminate. This is achieved by periodically
   calling <span class="function"><a href="win32_get_last_control_message.html" class="function">win32_get_last_control_message()</a></span> and handling the
   return code appropriately.
  </p>

  <div class="caution"><strong class="caution">Caution</strong>
   <p class="para">
    Since version 0.2.0, this function work only in &quot;cli&quot; SAPI. On other SAPI 
    this function is disabled.
   </p>
  </div>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.win32-start-service-ctrl-dispatcher-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">name</code></dt>

     <dd>

      <p class="para">
       The short-name of the service, as registered by
       <span class="function"><a href="win32_create_service.html" class="function">win32_create_service()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">gracefulMode</code></dt>

     <dd>

      <p class="para">
       <strong><code>TRUE</code></strong> for exit graceful. <strong><code>FALSE</code></strong> for exit with error. See 
       <span class="function"><a href="win32_set_service_exit_mode.html" class="function">win32_set_service_exit_mode()</a></span> for more details.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.win32-start-service-ctrl-dispatcher-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    成功时返回 <strong><code>TRUE</code></strong>，参数错误时返回 <strong><code>FALSE</code></strong>，或失败时返回一个 <a href="win32service.constants.errors.html" class="link">Win32 错误码</a>。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.win32-start-service-ctrl-dispatcher-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   If SAPI is not <em>&quot;cli&quot;</em>, this function emits an <strong><code>E_ERROR</code></strong> level error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.win32-start-service-ctrl-dispatcher-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example.dotnet">
    <p><strong>Example #1 A <span class="function"><strong>win32_start_service_ctrl_dispatcher()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Check if the service is runnig under the SCM.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">win32_start_service_ctrl_dispatcher</span><span style="color: #007700">(</span><span style="color: #DD0000">'dummyphp'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;die(</span><span style="color: #DD0000">"I'm&nbsp;probably&nbsp;not&nbsp;running&nbsp;under&nbsp;the&nbsp;service&nbsp;control&nbsp;manager"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">win32_set_service_status</span><span style="color: #007700">(</span><span style="color: #0000BB">WIN32_SERVICE_START_PENDING</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Some&nbsp;lengthy&nbsp;process&nbsp;to&nbsp;get&nbsp;this&nbsp;service&nbsp;up&nbsp;and&nbsp;running.<br /><br /></span><span style="color: #0000BB">win32_set_service_status</span><span style="color: #007700">(</span><span style="color: #0000BB">WIN32_SERVICE_RUNNING</span><span style="color: #007700">);<br /><br />while&nbsp;(</span><span style="color: #0000BB">WIN32_SERVICE_CONTROL_STOP&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #0000BB">win32_get_last_control_message</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;do&nbsp;some&nbsp;work&nbsp;here,&nbsp;trying&nbsp;not&nbsp;to&nbsp;take&nbsp;more&nbsp;than&nbsp;around&nbsp;30&nbsp;seconds<br />&nbsp;&nbsp;#&nbsp;before&nbsp;coming&nbsp;back&nbsp;into&nbsp;the&nbsp;loop&nbsp;again<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.win32-start-service-ctrl-dispatcher-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>0.4.0</td>
       <td>
        The parameter <code class="parameter">gracefulMode</code> has been added.
       </td>
      </tr>

      <tr>
       <td>0.2.0</td>
       <td>
        This function works only in the <em>&quot;cli&quot;</em> SAPI.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.win32-start-service-ctrl-dispatcher-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="win32_set_service_status.html" class="function" rel="rdfs-seeAlso">win32_set_service_status()</a> - Update the service status</span></li>
    <li class="member"><span class="function"><a href="win32_get_last_control_message.html" class="function" rel="rdfs-seeAlso">win32_get_last_control_message()</a> - Returns the last control message that was sent to this service</span></li>
    <li class="member"><span class="function"><a href="win32_set_service_exit_mode.html" class="function" rel="rdfs-seeAlso">win32_set_service_exit_mode()</a> - Define or return the exit mode for the current running service</span></li>
    <li class="member"><span class="function"><a href="win32_set_service_exit_code.html" class="function" rel="rdfs-seeAlso">win32_set_service_exit_code()</a> - Define or return the exit code for the current running service</span></li>
    <li class="member"><a href="win32service.constants.errors.html" class="link">Win32 Error Codes</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>